package com.aps.util;

import java.util.Date;
import java.util.Random;

/**
 */
public class TestUtil {

    public static String orderNum() {
        return "ORDER" + DateUtil.formatDate(new Date(), "yyyyMMddhhmmssSSS");
    }

    public static String tableNum() {
        return "T" + new Random().nextInt(20);
    }

    public static Integer getRandom(int min, int max) {
        Random random = new Random();
        int s = random.nextInt(max) % (max - min + 1) + min;
        return s;

    }

    /**
     * 通过指定的多少内的随机数及生成个数及是否从0开始,返回不重复的随机数数组
     * @param randomVal --- 多少内的随机数
     * @param arrSize  --- 数组长度
     * @param startZero  --- 是否从0开始
     * @return
     * @throws IllegalAccessException
     */
    public static Integer[] random(int randomVal, int arrSize, boolean startZero){

        Integer[] arr = new Integer[arrSize];

        for (int i = 0; true;) {
            int val = new Random().nextInt(randomVal);
            if (!startZero) {
                val += 1;
            }
            boolean hasExist = false;
            if (i > 0) {
                for (int j = i - 1; j >= 0; j--) {
                    if (val == arr[j]) {
                        hasExist = true;
                        break;
                    }
                }
            }

            if (!hasExist) {
                arr[i++] = val;
            }
            if (i == arrSize) {
                break;
            }
        }
        return arr;
    }
}
